Use a bitfield for Widget::private_flags, ::state, ::saved_state
authorHavoc Pennington <hp@pobox.com>
Mon, 6 Sep 2010 23:15:51 +0000 (19:15 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 7 Sep 2010 04:13:11 +0000 (00:13 -0400)
This recovers 10 bits, since state and saved_state as uint8 both
wasted 5 bits. Now we can add 10 more flags.

Also, a possible future patch could just do 1-bit bitfields
for the private flags instead of using manual bit twiddling.

https://bugzilla.gnome.org/show_bug.cgi?id=628884

gtk/gtkwidget.h

index 220e39bcfb343038861ebefe4c5e0a328b9894c1..e5f722050e5cf82c612e1df0701074b6f2b5bc87 100644 (file)
@@ -256,27 +256,27 @@ struct _GtkWidget
    *  GtkObject pointer.
    */
   GtkObject object;
-  
-  /* 16 bits of internally used private flags.
-   * this will be packed into the same 4 byte alignment frame that
-   * state and saved_state go. we therefore don't waste any new
-   * space on this.
-   */
-  guint16 GSEAL (private_flags);
-  
-  /* The state of the widget. There are actually only
-   *  5 widget states (defined in "gtkenums.h").
+
+  /* internally used private flags. */
+  guint GSEAL (private_flags) : 16;
+
+  /* The state of the widget. There are only
+   *  5 widget states (defined in "gtkenums.h")
+   * so 3 bits.
    */
-  guint8 GSEAL (state);
-  
+  guint GSEAL (state) : 3;
+
   /* The saved state of the widget. When a widget's state
    *  is changed to GTK_STATE_INSENSITIVE via
    *  "gtk_widget_set_state" or "gtk_widget_set_sensitive"
    *  the old state is kept around in this field. The state
    *  will be restored once the widget gets sensitive again.
    */
-  guint8 GSEAL (saved_state);
-  
+  guint GSEAL (saved_state) : 3;
+
+  /* unused bits in our 32-bit block */
+  guint GSEAL (reserved) : 10;
+
   /* The widget's name. If the widget does not have a name
    *  (the name is NULL), then its name (as returned by
    *  "gtk_widget_get_name") is its class's name.